﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;

namespace Studio
{
	// Token: 0x02000559 RID: 1369
	public class UI_InfoPicker : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IEventSystemHandler
	{
		// Token: 0x1700043A RID: 1082
		// (get) Token: 0x060022F1 RID: 8945 RVA: 0x000D3BAC File Offset: 0x000D1DAC
		// (set) Token: 0x060022F2 RID: 8946 RVA: 0x000D3BB4 File Offset: 0x000D1DB4
		public bool isOn { get; private set; }

		// Token: 0x060022F3 RID: 8947 RVA: 0x000D3BC0 File Offset: 0x000D1DC0
		private void Start()
		{
			this.SearchCanvas();
		}

		// Token: 0x060022F4 RID: 8948 RVA: 0x000D3BC8 File Offset: 0x000D1DC8
		private void SearchCanvas()
		{
			GameObject gameObject = base.gameObject;
			for (;;)
			{
				Canvas component = gameObject.GetComponent<Canvas>();
				if (component)
				{
					break;
				}
				if (null == gameObject.transform.parent)
				{
					return;
				}
				gameObject = gameObject.transform.parent.gameObject;
			}
			this.rtCanvas = (gameObject.transform as RectTransform);
		}

		// Token: 0x060022F5 RID: 8949 RVA: 0x000D3C38 File Offset: 0x000D1E38
		private void SetImagePosition(Vector2 cursorPos)
		{
			if (null == this.rtCanvas)
			{
				return;
			}
			RectTransform rectTransform = base.transform as RectTransform;
			float value = (cursorPos.x - rectTransform.position.x) / this.rtCanvas.localScale.x;
			float value2 = (cursorPos.y - rectTransform.position.y) / this.rtCanvas.localScale.y;
			this.imagePos.x = Mathf.Clamp(value, 0f, rectTransform.sizeDelta.x);
			this.imagePos.y = Mathf.Clamp(value2, 0f, rectTransform.sizeDelta.y);
			this.imageRate.x = Mathf.InverseLerp(0f, rectTransform.sizeDelta.x, value);
			this.imageRate.y = Mathf.InverseLerp(0f, rectTransform.sizeDelta.y, value2);
		}

		// Token: 0x060022F6 RID: 8950 RVA: 0x000D3D54 File Offset: 0x000D1F54
		public void OnPointerDown(PointerEventData ped)
		{
			this.isOn = true;
			this.SetImagePosition(ped.position);
		}

		// Token: 0x060022F7 RID: 8951 RVA: 0x000D3D6C File Offset: 0x000D1F6C
		public void OnBeginDrag(PointerEventData ped)
		{
			this.SetImagePosition(ped.position);
		}

		// Token: 0x060022F8 RID: 8952 RVA: 0x000D3D7C File Offset: 0x000D1F7C
		public void OnDrag(PointerEventData ped)
		{
			this.SetImagePosition(ped.position);
		}

		// Token: 0x060022F9 RID: 8953 RVA: 0x000D3D8C File Offset: 0x000D1F8C
		public void OnEndDrag(PointerEventData ped)
		{
			this.SetImagePosition(ped.position);
		}

		// Token: 0x060022FA RID: 8954 RVA: 0x000D3D9C File Offset: 0x000D1F9C
		public void OnPointerUp(PointerEventData ped)
		{
			this.isOn = false;
			this.SetImagePosition(ped.position);
		}

		// Token: 0x04002402 RID: 9218
		public Vector2 imagePos = Vector2.zero;

		// Token: 0x04002403 RID: 9219
		public Vector2 imageRate = Vector2.zero;

		// Token: 0x04002404 RID: 9220
		public RectTransform rtCanvas;
	}
}
